import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home/index'
  },
  {
    path: '/home',
    component: HomeView,
    children: [
      {
        path: 'index',
        component: () => import('../views/index.vue'),
      },
      {
        path: 'car-estimate',
        component: () => import('../views/CarManagement/estimate.vue'),
        meta: {
          thumbs: ['车辆管理', '车况评估'],
          keepAlive: true,
        }
      },
      {
        path: 'car-management',
        component: () => import('../views/CarManagement/carmanagement.vue'),
        meta: {
          thumbs: ['车辆管理', '车辆列表']
        }
      },
      {
        path: 'car-update',
        component: () => import('../views/CarManagement/carupdate.vue'),
        meta: {
          thumbs: ['车辆管理', '车辆列表', '修改车辆信息']
        }
      },
      {
        path: 'member-list',
        component: () => import('../views/member/member-list.vue'),
        meta: {
          thumbs: ['员工管理', '员工列表']
        }
      },
      {
        path: 'member-add',
        component: () => import('../views/member/member-add.vue'),
        meta: {
          thumbs: ['员工管理', '员工列表', '新增员工']
        }
      },
      {
        path: 'customer-list',
        component: () => import('../views/Customer/customerlist.vue'),
        meta: {
          thumbs: ['客户管理', '客户列表']
        }
      },
      {
        path: 'user-add',
        component: () => import('../views/system/userAdd.vue'),
        meta: {
          thumbs: ['系统设定', '新增用户']
        }
      },
      {
        path: 'user-update',
        component: () => import('../views/system/update.vue'),
        meta: {
          thumbs: ['系统设定', '修改个人信息']
        }
      },
    ]
  },
  {
    path: '/user/login',
    name: 'login',
    component: () => import('../views/user/login.vue')
  },
  /* {
    path: '/1',
    component: () => import('../views/1.vue')
  }, */
  /* {
    path: '/4',
    component: () => import('../views/4.vue')
  },
  {
    path: '/5',
    component: () => import('../views/5.vue')
  }, */
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
import store from '@/store'
//设置全局前置守卫  每当路由跳转时执行 (在显示目标组件之前执行)
router.beforeEach((to, from, next) => {
  if (to.path == '/user/login' || store.state.user) next() // 向后继续执行，显示登录页面 
  //不是访问登录，就需要验证vuex用户
  else router.push('/user/login')
})

export default router
